﻿package mortal.game.view.guild.cellrender
{
    import Message.Game.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.events.*;
    import com.mui.manager.*;
    import extend.language.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.item.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.guild.otherpanel.*;
    import mortal.game.view.guild.util.*;
    import mortal.mvc.core.*;

    public class GuildResourceAllotRenderer extends GCellRenderer
    {
        private const MAX_ITEM_NUM:int = 4;
        private var _avatar:GImageBitmap;
        private var _lv:GTextFiled;
        private var _name:GTextFiled;
        private var _post:GTextFiled;
        private var _contribution:GTextFiled;
        private var _starPanel1:StarPanel;
        private var _starPanel2:StarPanel;
        private var _starPanel3:StarPanel;
        private var _items:Vector.<BaseItem>;
        private var _lineBox:Vector.<LineBox>;

        public function GuildResourceAllotRenderer()
        {
            this._items = new Vector.<BaseItem>;
            this._lineBox = new Vector.<LineBox>;
            return;
        }// end function

        private function onMoveIn(event:DragEvent) : void
        {
            var dropItem:BaseItem;
            var playerItem:SPlayerItem;
            var onYes:Function;
            var e:* = event;
            onYes = function (param1:int) : void
            {
                dropItem.itemData = new ItemData(playerItem.itemCode);
                dropItem.amount = param1;
                GuildResourceRecordUitl.instance.addItems(playerItem, param1, itemData.playerId, _items.indexOf(dropItem));
                return;
            }// end function
            ;
            var dragItem:* = e.dragItem as BaseItem;
            dropItem = e.dropItem as BaseItem;
            if (dragItem.parent is GuildItemCellRenderer)
            {
                playerItem = ItemData(e.dragSouce).serverData;
                if (playerItem.itemAmount > 1)
                {
                    SelectNumPanel.instance.show();
                    SelectNumPanel.instance.setData(e.dragSouce as ItemData, Language.getString(70533), Language.getString(70534), onYes);
                    return;
                }
                this.onYes(playerItem.itemAmount);
            }
            return;
        }// end function

        private function onThrowGoods(event:DragEvent) : void
        {
            var dragItem:BaseItem;
            var itemInfo:ItemData;
            var onYes:Function;
            var e:* = event;
            onYes = function (param1:int) : void
            {
                if (itemInfo.itemAmount > param1)
                {
                    itemInfo.itemAmount = itemInfo.itemAmount - param1;
                    dragItem.itemData = itemInfo;
                }
                else
                {
                    dragItem.itemData = null;
                }
                GuildResourceRecordUitl.instance.delItems(itemInfo.itemCode, param1, itemData.playerId, _items.indexOf(dragItem));
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildResourceSelectItemUpdata));
                return;
            }// end function
            ;
            dragItem = e.dragItem as BaseItem;
            itemInfo = e.dragSouce as ItemData;
            itemInfo.itemAmount = dragItem.amount;
            if (itemInfo.itemAmount > 1)
            {
                SelectNumPanel.instance.show();
                SelectNumPanel.instance.setData(itemInfo, Language.getString(70533), Language.getString(70534), onYes);
                return;
            }
            this.onYes(itemInfo.itemAmount);
            return;
        }// end function

        private function delAllLineBox() : void
        {
            var _loc_1:LineBox = null;
            for each (_loc_1 in this._lineBox)
            {
                
                DisplayUtil.removeMe(_loc_1);
                EffectManager.disposeLineBox(_loc_1);
            }
            this._lineBox.splice(0, this._lineBox.length);
            return;
        }// end function

        private function get itemData() : SGuildParticipationInfo
        {
            return data as SGuildParticipationInfo;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_5:BaseItem = null;
            var _loc_6:SPlayerItem = null;
            var _loc_7:LineBox = null;
            super.data = param1 as SGuildParticipationInfo;
            this._name.text = this.itemData.name;
            this._lv.text = this.itemData.level.toString();
            this._post.text = GameDefConfig.instance.getItem("EGuildPostion", this.itemData.position).text;
            this._contribution.text = this.itemData.contributionWeek.toString();
            this._avatar.imgUrl = AvatarUtil.getPlayerAvatarUrl(this.itemData.carrer, this.itemData.sex, AvatarUtil.Small);
            var _loc_2:int = 14;
            var _loc_3:* = DailyConfig.instance.getWeekTimeById(GameDefConfig.instance.getDailyViewConfigId(2));
            var _loc_4:* = DailyConfig.instance.getWeekTimeById(GameDefConfig.instance.getDailyViewConfigId(3));
            this._starPanel1.setStarNum(1, this.itemData.worldBossTimes / _loc_2);
            this._starPanel2.setStarNum(1, this.itemData.guildWarTimes / _loc_3);
            this._starPanel3.setStarNum(1, this.itemData.guildTaskTimes / _loc_4);
            ToolTipsManager.unregister(this._starPanel1);
            ToolTipsManager.unregister(this._starPanel2);
            ToolTipsManager.unregister(this._starPanel3);
            ToolTipsManager.register(this._starPanel1, null, Language.getStringByParam(70537, this.itemData.worldBossTimes, _loc_2));
            ToolTipsManager.register(this._starPanel2, null, Language.getStringByParam(70538, this.itemData.guildWarTimes, _loc_3));
            ToolTipsManager.register(this._starPanel3, null, Language.getStringByParam(70539, this.itemData.guildTaskTimes, _loc_4));
            this.delAllLineBox();
            var _loc_8:int = 0;
            while (_loc_8 < this.MAX_ITEM_NUM)
            {
                
                _loc_5 = this._items[_loc_8];
                if (GuildResourceRecordUitl.instance.getPlayerItem(this.itemData.playerId, _loc_8))
                {
                    _loc_6 = new SPlayerItem();
                    ClassTypesUtil.copyClassValue(_loc_6, GuildResourceRecordUitl.instance.getPlayerItem(this.itemData.playerId, _loc_8));
                    _loc_5.itemData = new ItemData(_loc_6);
                    if (GuildResourceRecordUitl.instance.getNotEnoughMapNum(_loc_6.itemCode) > -1)
                    {
                        _loc_7 = EffectManager.getLineBox(_loc_5.width, _loc_5.height);
                        UIFactory.setObjAttri(_loc_7, _loc_5.x, _loc_5.y, -1, -1, this);
                        this._lineBox.push(_loc_7);
                    }
                }
                else
                {
                    _loc_5.itemData = null;
                }
                _loc_8++;
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_2:BaseItem = null;
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.PackItemBg, 5, 5, this));
            pushUIToDisposeVec(UIFactory.bg(20, 50, 468, 2, this, ImagesConst.SplitLine4));
            this._name = UIFactory.gTextField("", 50, 5, 100, 20, this);
            this._post = UIFactory.gTextField("", 50, 25, 100, 20, this);
            this._contribution = UIFactory.gTextField("", 140, 20, 55, 20, this, GlobalStyle.textFormatBai.center());
            this._avatar = UIFactory.gImageBitmap("", 5.5, 5.5, this);
            this._lv = UIFactory.gTextField("", 5, 28, 30, 20, this, GlobalStyle.textFormatBai);
            this._starPanel1 = UIFactory.getUICompoment(StarPanel, 216, 15, this);
            this._starPanel1.mouseEnabled = true;
            this._starPanel1.setStarStyle(ImagesConst.GuildWarStarM, ImagesConst.GuildWarStarMGray, 25);
            this._starPanel2 = UIFactory.getUICompoment(StarPanel, 241, 15, this);
            this._starPanel2.mouseEnabled = true;
            this._starPanel2.setStarStyle(ImagesConst.GuildWarStarM, ImagesConst.GuildWarStarMGray, 25);
            this._starPanel3 = UIFactory.getUICompoment(StarPanel, 266, 15, this);
            this._starPanel3.mouseEnabled = true;
            this._starPanel3.setStarStyle(ImagesConst.GuildWarStarM, ImagesConst.GuildWarStarMGray, 25);
            var _loc_1:int = 0;
            while (_loc_1 < this.MAX_ITEM_NUM)
            {
                
                _loc_2 = UIFactory.baseItem(320 + _loc_1 * 45, 5, 32, 31, this);
                _loc_2.setItemStyle();
                _loc_2.isDragAble = true;
                _loc_2.isDropAble = true;
                _loc_2.configEventListener(DragEvent.Event_Move_In, this.onMoveIn);
                _loc_2.configEventListener(DragEvent.Event_Throw_goods, this.onThrowGoods);
                this._items.push(_loc_2);
                _loc_1++;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_2:BaseItem = null;
            super.disposeImpl(param1);
            ToolTipsManager.unregister(this._starPanel1);
            ToolTipsManager.unregister(this._starPanel2);
            ToolTipsManager.unregister(this._starPanel3);
            this._name.dispose(param1);
            this._post.dispose(param1);
            this._contribution.dispose(param1);
            this._avatar.dispose(param1);
            this._starPanel1.dispose(param1);
            this._starPanel2.dispose(param1);
            this._starPanel3.dispose(param1);
            this.delAllLineBox();
            for each (_loc_2 in this._items)
            {
                
                _loc_2.dispose(param1);
            }
            this._items.splice(0, this._items.length);
            return;
        }// end function

    }
}
